package com.bhs.sansonglogistics.dialog;

import android.annotation.SuppressLint;
import android.content.Context;
import android.view.View;
import android.widget.ImageView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.bhs.sansonglogistics.R;
import com.bhs.sansonglogistics.base.BaseActivity;
import com.bhs.sansonglogistics.bean.ArriveBean;
import com.bhs.sansonglogistics.net.NetCallBack;
import com.bhs.sansonglogistics.ui.adapter.ArriveAdapter;
import com.bhs.sansonglogistics.ui.adapter.OrderGoodsAdapter;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.lxj.xpopup.core.BottomPopupView;

import java.util.ArrayList;
import java.util.List;

import okhttp3.ResponseBody;
import retrofit2.Response;

/**
 * 选择到站地址
 */
public class BottomSelectArriveAddressDialog extends BottomPopupView implements NetCallBack {

    private RecyclerView mRvList;
    private List<ArriveBean> list = new ArrayList();
    private ArriveAdapter adapter;
    private MyClickListener2 myClickListener;


    public BottomSelectArriveAddressDialog(@NonNull Context context, List<ArriveBean> list) {
        super(context);
        this.list.addAll(list);
    }

    @Override
    protected void onCreate() {
        super.onCreate();
        initView();
    }

    @Override
    protected int getImplLayoutId() {
        return R.layout.dialog_bottom_select_arrive_address;
    }

    private void initView() {
        findViewById(R.id.iv_close).setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View view) {
                dismiss();
            }
        });
        mRvList = findViewById(R.id.rv_list);

        adapter = new ArriveAdapter( list);
        mRvList.setAdapter(adapter);
        mRvList.setLayoutManager(new LinearLayoutManager(getContext()));
        adapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
            @SuppressLint("NotifyDataSetChanged")
            @Override
            public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
                for (ArriveBean arriveBean : list) {
                    arriveBean.setChecked(false);
                }
                list.get(position).setChecked(true);
                adapter.notifyDataSetChanged();
                ArriveBean data = list.get(position);
                String info = String.format("到站公司：%s\n线路经理：%s\n到站电话：%s\n到站地址：%s",
                        data.getOutlets_name(),data.getOutlets_contact(),data.getOutlets_mobile(),data.getOutlets_address());
                myClickListener.onClick(String.valueOf(data.getOutlets_id()),info);
                dismiss();
            }
        });
    }

    public void setMyClickListener(@Nullable MyClickListener2 l) {
        this.myClickListener = l;
    }

    @Override
    public void onResponse(int requestCode, String json, Response<ResponseBody> response) throws Exception {

    }

    @Override
    public void onFailure(int requestCode) {

    }
}
